package com.sdc.autohome.controller;

import com.alibaba.fastjson.JSONObject;
import com.sdc.autohome.bean.ClueBack;
import com.sdc.autohome.service.ClueBackService;
import com.sdc.autohome.utils.ClientRequestData;
import com.sdc.autohome.utils.DateUtils;
import org.junit.jupiter.api.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

@Component
@Order(1)
public class AutoHomeInfoController implements ApplicationRunner {
    @Autowired
    private ClueBackService clueBackService;
    @Autowired
    private ClientRequestData clientRequestData;

    private static final Logger logger = Logger.getLogger(AutoHomeInfoController.class.getName());

    public void testInsertDealerScore(String date) throws IOException {


        List<ClueBack> byBs = clueBackService.findByBs(date);
        if (byBs.size() >= 1000) {
            logger.info("clue_back查询暂数据条数：" +  byBs.size() );
            JSONObject jsonData = clientRequestData.getDealerData(byBs);
//            logger.info("推送接口返回内容：" + jsonData );
        } else if (byBs.size() > 0) {
            logger.info("clue_back查询暂数据条数：" +  byBs.size() + " 小于1000条，存入下一天");
            System.exit(0);
        } else {
            logger.info("clue_back查询暂无数据" );
            System.exit(0);
        }
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        String s = DateUtils.dateUtily();
        logger.info("参数时间获取前一天日期yyyymmdd：" + s);
        testInsertDealerScore(s);
    }
}
